<template>
  <div class="zhebi">
    <div class="play-list">
      <div class="title">播放列表</div>
      <div class="list">
        <div>
          <div class="item" v-for="(item, index) in playItem" :key="index">
            <div class="no-img" v-if="index == 0"></div>
            <div class="no" v-else>{{ index + 1 }}</div>
            <div class="info">
              <div class="tit-current" v-if="index == 0">
                <span v-if="item.deptName">{{ item.deptName }} -</span>
                <span class="p">{{ item.resourceName }}</span>
              </div>
              <div class="tit" v-else>
                <span v-if="item.deptName">{{ item.deptName }} -</span>
                <span class="p">{{ item.resourceName }}</span>
              </div>
              <div class="long-pd">
                <div class="long-pd_left" style="width: calc(100% - 80px)">
                  <span>{{ item.duration }}</span
                  ><span>/</span><span>{{ item.resourceTime }}</span>
                  {{ item.companyName }}
                </div>
                <div
                  class="long-pd_right"
                  v-if="index > 0 && isMyDianbo(item.playUserId)"
                >
                  <span
                    v-if="index > 0 && isMyDianbo(item.playUserId)"
                    @click="removeDianBo(item.id)"
                    style="color: #d81518"
                    >取消排队</span
                  >
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="close" @click="closePlayList"></div>
    </div>
  </div>
  <Tips :message="message" v-if="message" />
</template>
<script>
import pubsub from "pubsub-js";
import { ref, reactive, toRaw, onUnmounted, computed } from "vue";
import { useStore } from "vuex";
import axios from "axios";
import { timeEvent, formatSeconds } from "../utils/util";
export default {
  name: "playList",
  props: {
    playIndex: Number,
  },
  setup(props) {
    const message = ref("");
    const store = reactive(useStore());
    const state = store.state;
    const playItem = computed(() => {
      return state.playList[state.scene].data.list;
    })
    const closePlayList = () => {
      pubsub.publish("player", false);
    };
    const playIndex = props.playIndex;
    const isMyDianbo = (uid) => {
      return state.userId === uid || state.userId === "9999";
    };
    onUnmounted(() => {
      clearInterval(timer);
    });
    var timer;
    if (timer) {
      clearInterval(timer);
    }
    const removeDianBo = (id) => {
      axios
        .post("/mguo/audio/cancelAudio", {
          resourceId: id,
          userId: state.userId,
        })
        .then((response) => {
          if (response.data.msg && response.data.msg == "success") {
          } else {
            message.value = "取消失败," + response.data.msg;
          }
          const timer = setTimeout(() => {
            message.value = null;
            clearInterval(timer);
          }, 2000);
        });
    };
    return {
      closePlayList,
      playItem,
      playIndex,
      isMyDianbo,
      removeDianBo,
    };
  },
};
</script>
<style scoped lang="scss">
.zhebi {
  background: rgba(0, 0, 0, 0.8);
  height: 100%;
  width: 100%;
  position: fixed;
  left: 0;
  top: 0;

  .play-list {
    position: absolute;
    padding-bottom: 20px;
    width: 330px;
    color: black;
    left: 50%;
    background: #fdc830;
    transform: translateX(-50%);
    top: 13%;
    border-radius: 8px;
    .close {
      background: url(../images/icon-close.png) no-repeat;
      position: absolute;
      bottom: -50px;
      width: 38px;
      height: 38px;
      left: calc(50% - 19px);
    }
    .title {
      font-weight: bold;
      height: 60px;
      line-height: 60px;
      text-align: center;
    }
    .list {
      padding: 0 15px;
      font-size: 14px;
      max-height: 350px;
      overflow: auto;
      .item {
        display: flex;
        align-items: center;
        margin-bottom: 20px;
        .no {
          width: 20px;
          font-weight: bold;
          padding: 0 5px;
          height: 50px;
          line-height: 50px;
        }
        .no-img {
          width: 30px;
          background: url(../images/frame.png) no-repeat 10px;
          height: 50px;
          position: relative;
          left: -10px;
        }
        .info {
          text-align: left;
          padding-left: 10px;
          width: 100%;
          .tit {
            font-weight: bold;
            padding: 5px 0;
            span {
              padding: 0 5px;
            }
          }
          .tit-current {
            color: #ff4a4a;
            font-weight: bold;
            padding: 5px 0;
            span {
              padding: 0 5px;
            }
          }
          .long-pd {
            font-size: 12px;
            opacity: 0.8;
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;
            &_right {
              width: 80px;
              text-align: right;
            }
            &_left {
              flex: 1;
              width: 100%;
            }
            span {
              padding: 0 3px;
            }
            span:nth-child(1) {
              padding-left: 0;
            }
            .p {
              // padding-left: 22px;
            }
          }
        }
      }
    }
  }
}
</style>
